package gsp420;

import java.awt.Color;
import java.awt.Graphics;

public class Square extends Entity
{
	public Square(double x, double y, int rad)
	{
		super(x, y);
		this.rad = rad;
	}

	int rad;
	// TODO draw an image
	@Override
	public void draw(Graphics g)
	{
		g.setColor(Color.RED);
		g.fillRect((int)p.x-rad, (int)p.y-rad, rad*2, rad*2);
	}

	@Override
	public boolean isCollidingWith(Entity e)
	{
		if(e instanceof Circle)
		{
			Circle c = (Circle)e;
			return c.isCollidingWith(this);
		}
		else if(e instanceof Square)
		{
			Square s = (Square)e;
			double l = p.x-rad, r = p.x+rad, t = p.y-rad, b = p.y+rad;
			double l2 = s.p.x-s.rad, r2=s.p.x+s.rad, t2 = s.p.y-rad, b2 = s.p.y+s.rad;
			return ! (l > r2 || r < l2 || t > b2 || b < t2 );
		}			
		return false;
	}

}
